package com.blacktech.dbu.meta.entity;

import com.blacktech.dbu.core.common.BaseEntity;
import com.blacktech.dbu.core.dict.ConstraintType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

/**
 * 数据约束信息
 *
 * @author yanyunsong
 */
@Data
@Entity
@Table(name = "dbu_constraint")
@EqualsAndHashCode(callSuper = true)
public class DbuConstraint extends BaseEntity {

    /**
     * 约束名称
     */
    @Column(name = "constraint_name")
    private String constraintName;

    /**
     * 约束类型
     */
    @Column(name = "constraint_type")
    @Enumerated(EnumType.STRING)
    private ConstraintType constraintType;

    /**
     * 约束涉及的字段列表
     */
    @ManyToMany
    @JoinTable(name = "dbu_constraint_column", joinColumns = @JoinColumn(name = "constraint_id"), inverseJoinColumns = @JoinColumn(name = "column_id"))
    @JsonIgnore
    private List<DbuColumn> columnList;

    /**
     * 关联的数据表
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "table_id")
    @JsonIgnore
    private DbuTable table;
}